]>
Commit | Line | Data |
---|---|---|
98f09799 RBR |
1 | /* |
2 | Copyright (C) 2024 Rubén Beltrán del Río | |
3 | ||
4 | This program is free software: you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation, either version 3 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program. If not, see https://map.tranquil.systems. | |
16 | */ | |
5e8ff485 RBR |
17 | import SwiftUI |
18 | ||
19 | struct MapAxes: View { | |
20 | ||
5e8ff485 RBR |
21 | let mapSize: CGSize |
22 | let lineWidth: CGFloat | |
23 | let evolution: Stage | |
24 | let stages: [CGFloat] | |
77d0155b | 25 | let stageHeight = CGFloat(100.0) |
5e8ff485 RBR |
26 | let padding = CGFloat(5.0) |
27 | ||
5e8ff485 RBR |
28 | var body: some View { |
29 | ZStack(alignment: .topLeading) { | |
30 | ||
31 | // Axis Lines | |
32 | Path { path in | |
33 | path.move(to: CGPoint(x: 0, y: 0)) | |
34 | path.addLine(to: CGPoint(x: 0, y: mapSize.height)) | |
35 | path.addLine(to: CGPoint(x: mapSize.width, y: mapSize.height)) | |
36 | path.move(to: CGPoint(x: mapSize.width, y: mapSize.height)) | |
37 | path.closeSubpath() | |
fdb4633d | 38 | }.stroke(Color.map.axisColor, lineWidth: lineWidth * 2) |
5e8ff485 RBR |
39 | |
40 | // Y Labels | |
e2c37ac1 RBR |
41 | Text("Visible").font(.theme.axisLabel).foregroundColor(.map.labelColor).rotationEffect( |
42 | Angle(degrees: -90.0) | |
43 | ) | |
44 | .offset(CGSize(width: -35.0, height: 0.0)) | |
45 | Text("Invisible").font(.theme.axisLabel).foregroundColor(.map.labelColor).rotationEffect( | |
46 | Angle(degrees: -90.0) | |
47 | ) | |
48 | .offset(CGSize(width: -40.0, height: mapSize.height - 20)) | |
5e8ff485 RBR |
49 | |
50 | // X Labels | |
51 | ||
52 | Text("Uncharted") | |
fdb4633d RBR |
53 | .font(.theme.axisLabel) |
54 | .foregroundColor(.map.labelColor) | |
77d0155b RBR |
55 | .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading) |
56 | .offset(CGSize(width: 0.0, height: -stageHeight / 4.0)) | |
5e8ff485 | 57 | Text("Industrialised") |
fdb4633d RBR |
58 | .font(.theme.axisLabel) |
59 | .foregroundColor(.map.labelColor) | |
77d0155b RBR |
60 | .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading) |
61 | .offset(CGSize(width: mapSize.width - 100.0, height: -stageHeight / 4.0)) | |
5e8ff485 RBR |
62 | |
63 | Text(evolution.i) | |
fdb4633d RBR |
64 | .font(.theme.axisLabel) |
65 | .foregroundColor(.map.labelColor) | |
5e8ff485 RBR |
66 | .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading) |
67 | .offset(CGSize(width: 0.0, height: mapSize.height + padding)) | |
68 | ||
69 | Text(evolution.ii) | |
fdb4633d RBR |
70 | .font(.theme.axisLabel) |
71 | .foregroundColor(.map.labelColor) | |
5e8ff485 RBR |
72 | .frame(width: w(stages[1]) - w(stages[0]), height: stageHeight, alignment: .topLeading) |
73 | .offset(CGSize(width: w(stages[0]), height: mapSize.height + padding)) | |
74 | ||
75 | Text(evolution.iii) | |
fdb4633d RBR |
76 | .font(.theme.axisLabel) |
77 | .foregroundColor(.map.labelColor) | |
5e8ff485 RBR |
78 | .frame(width: w(stages[2]) - w(stages[1]), height: stageHeight, alignment: .topLeading) |
79 | .offset(CGSize(width: w(stages[1]), height: mapSize.height + padding)) | |
80 | ||
81 | Text(evolution.iv) | |
fdb4633d RBR |
82 | .font(.theme.axisLabel) |
83 | .foregroundColor(.map.labelColor) | |
5e8ff485 RBR |
84 | .frame(width: mapSize.width - w(stages[2]), height: stageHeight, alignment: .topLeading) |
85 | .offset(CGSize(width: w(stages[2]), height: mapSize.height + padding)) | |
86 | } | |
87 | } | |
88 | ||
89 | func w(_ dimension: CGFloat) -> CGFloat { | |
90 | max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) | |
91 | } | |
92 | } | |
93 | ||
e2c37ac1 RBR |
94 | #Preview { |
95 | MapAxes( | |
96 | mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0), | |
97 | evolution: Stage.stages(.general), stages: [25.0, 50.0, 75.0] | |
98 | ).padding(50.0) | |
5e8ff485 | 99 | } |